package jdbc;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;

import org.apache.cassandra.utils.Hex;

public class IndexDriverTest {

	/**
	 * @param args
	 * @throws SQLException 
	 * @throws NullPointerException 
	 */
	public static void main(String[] args) throws Exception {
		String host=System.getProperty("url","jdbc:laud://192.168.106.247:9170?data_port=9091");
		Class.forName("cn.edu.thu.laud.jdbc.LaUDDriver");
		Connection con = DriverManager.getConnection(host, "", "");
		Statement statement=con.createStatement();
		
		ResultSet rSet;
		statement.execute("use imageKeyspace");
//		try{
//		statement.execute("drop index cedd_cedd_idx");
//		}catch(Exception e){
//			
//		}
//		statement.execute("create index on cedd(cedd) "
//								+"with 'class_name'='cn.edu.thu.laud.lasql.index.LaUDIndex'" 
//								+" and 'implemention_class'='cn.edu.thu.laud.LaUDDistributedHDSearcherForIntegration.LaUDDistributedHDIndexerImage'" 
//								+"and 'featureType'='3'"
//				+"");
		ByteBuffer buffer=ByteBuffer.allocate(Double.SIZE*144);
			Random random=new Random(System.currentTimeMillis());
			for(int i=0;i<144;i++){
				buffer.putDouble(1.1);
			}
//			
		byte[] bytes=new byte[1152];
		buffer.position(0);
		for(int i=0;i<1152;i++){
			bytes[i]=buffer.get();
		}
		statement.execute(String.format("select uid from cedd where cedd='%s'",Hex.bytesToHex(bytes)));
//		statement.execute(String.format("select count(*) from cedd "));
		rSet=statement.getResultSet();
		System.out.println("begin select.");
		while(rSet.next()){
			System.out.println(rSet.getObject(1));
		}
		rSet.close();

		



		statement.close();

		System.err.println("-------------------close-------------------------");
		con.close();
	}

	
}
